<template>
	<view class="order-page">
		<view class="head-top">
			<u-navbar title="订单详情" :placeholder="true" bgColor="rgba(0,0,0,0.0)" :autoBack="true">
			</u-navbar>
			<view class="haed-title">
				<image src="https://m.lqvvvv.com/assets/static/my/clock.png" mode=""></image>
				<view v-if="info.status == 'created'">待支付</view>
				<text v-if="info.status == 'paid' && info.use_status == 0">待核销</text>
				<text v-if="info.status == 'paid' && info.use_status == 1">已核销</text>
				<view v-if="info.status == 'cancelled'">已取消</view>
			</view>
		</view>
		<view class="content">
			<view class="coupons">
				<view class="coupons-title" v-if="info.shop">
					{{info.shop.title}}
				</view>
				<view class="package" v-if="info.product">
					<image :src="'https://m.lqvvvv.com'+info.product.images" mode=""></image>
					<view class="package-right">
						<view class="right-title">
							{{info.product.name ||'物品名称'}}
						</view>
						<view class="tips">
							随时退 过期退
						</view>
						<view class="price-box" v-if="info.status == 'created'">
							<view></view>
							<view class="price-right">
								<text class="price-text">金额</text>
								<text class="price">￥{{info.price || '0.00'}}</text>
							</view>
						</view>
						<view class="price-box" v-else>
							<view></view>
							<view class="price-right">
								<text class="price-text">实付</text>
								<text class="price">￥{{info.price || '0.00'}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="qr-code" v-if="info.status != 'created'&&info.status != 'cancelled'">
					<image class="code" :src="QRimage" mode=""></image>
				</view>
				<view class="stay">
					<view class="stay-left">
						<view v-if="info.status == 'paid' && info.use_status == 0">
							待使用
						</view>
						<view v-if="info.status == 'paid' && info.use_status == 1">
							已使用
						</view>
					</view>
					<view class="refund" @click="cancel(info.orderid)" v-if="info.status != 'created'&&info.status != 'cancelled'">
						申请退款
					</view>
				</view>
			</view>
			<view class="notice-tips">
				<view class="notice">
					<view>
						使用须知
					</view>
				</view>
				<view class="guarantee">
					为了保障您的权益，到店消费前请不要将二维码提供给商户
				</view>
			</view>
			<view class="order">
				<view class="order-title">
					订单信息
				</view>
				<view class="order-info">
					<view class="info-item">
						<view>
							订单编号：{{info.orderid || '000000000000'}}
						</view>
						<view>

						</view>
						<u-icon @click="gocopy(info.orderid)" name="order" color="#000000" size="18"></u-icon>
					</view>
					<view class="info-item">
						交易快照：当发生交易纠纷时可作为交易凭证
					</view>
					<view class="info-item">
						下单时间：{{$u.timeFormat(info.paytime, 'yyyy-mm-dd hh:MM:ss')}}
					</view>
				</view>
			</view>
			<view class="merchants" @click="gotel(info.shop.mobile)"
				v-if="info.status != 'created'&&info.status != 'cancelled'">
				电话联系商家
			</view>
			<view class="btn-box" v-else-if="info.status == 'created'">
				<view class="btn1" @click="cancel(info.orderid)">
					取消订单
				</view>
				<view class="btn2" @click="gopay(info.orderid,info.paytype)">
					支付
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import QR from "@/codes/utils/wxqrcode.js" // 二维码生成器  
	export default {
		data() {
			return {
				id: '',
				QRimage: '', //二维码
				info: {}
			}
		},
		onLoad(e) {
			this.id = e.id
			this.shopinfo(e.id)
		},
		methods: {
			cancel(id){
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否取消订单！',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								mask:true
							})
							let params = {
								orderid: id
							}
							app.$Request({
								method: 'POST',
								url: '/api/shop_order/cancel',
								data: params,
								ismsg: true,
							}).then(res => {
								uni.hideLoading()
								if (res.code == 1) {
									app.shopinfo()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			gopay(orderid, paytype) {
				uni.showLoading({
					mask: true
				})
				let params = {
					orderid: orderid,
					// #ifdef APP
					method: 'app',
					// #endif
					// #ifdef H5
					method: 'web',
					// #endif
					// #ifdef MP-WEIXIN
					method: 'miniapp',
					// #endif
					paytype: paytype
				}
				this.$Request({
					method: 'POST',
					url: '/api/shop_order/pay',
					data: params,
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.shopinfo()
					}
				})
			},
			gotel(e) {
				uni.makePhoneCall({
					phoneNumber: e
				})
			},
			gocopy(number) {
				uni.setClipboardData({
					data: number,
					success: function() {
						uni.showToast({
							title: '复制成功！',
							icon: 'none'
						})
					}
				});
			},
			getqr() {
				let qrimg = this.info.orderid
				this.QRimage = QR.createQrCodeImg(qrimg, {
					size: parseInt(200),
					typeNumber: 7
				})
			},
			shopinfo(id) {
				let params = {
					orderid: this.id,
				}
				this.$Request({
					method: 'POST',
					url: '/api/shop_order/getDetail',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
						this.getqr()
					}
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.order-page {
		min-height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/nav-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 900rpx;
		background-color: #F7F8FC;

		.head-top {
			padding: 30rpx;

			.haed-title {
				display: flex;
				align-items: center;
				color: #333;
				font-weight: 700;
				font-size: 36rpx;

				image {
					width: 37rpx;
					height: 37rpx;
					margin-right: 10rpx;
				}
			}
		}

		.content {
			padding: 30rpx;

			.coupons {
				padding: 30rpx;
				background-color: #fff;
				border-radius: 30rpx;

				.coupons-title {
					color: #333333;
					font-size: 28rpx;
					font-weight: 700;
				}

				.package {
					width: 100%;
					display: flex;
					align-items: center;
					margin-top: 40rpx;
					border-bottom: 1rpx dashed #CCCCCC;
					padding-bottom: 30rpx;

					image {
						width: 126rpx;
						height: 126rpx;
						border-radius: 10rpx;
						margin-right: 30rpx;
					}

					.package-right {
						width: 80%;


						.right-title {
							font-size: 26rpx;
							color: #333333;
							font-weight: 700;
						}

						.tips {
							color: #999999;
							font-size: 24rpx;
							margin-top: 10rpx;
						}

						.price-box {
							margin-top: 10rpx;
							display: flex;
							justify-content: space-between;

							.price-text {
								margin-right: 10rpx;
							}

							.price {
								color: #FF2529;
							}
						}
					}
				}

				.qr-code {
					padding: 30rpx;
					display: flex;
					justify-content: center;

					.code {
						width: 244rpx;
						height: 244rpx;
					}
				}

				.stay {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.stay-left {
						display: flex;
						align-items: center;
						font-size: 28rpx;
						font-weight: 700;
						color: #333333;
					}

					.refund {
						font-size: 24rpx;
						font-weight: 700;
						color: #333333;
						padding: 10rpx 20rpx;
						border: 1rpx solid #E1E1E1;
						border-radius: 10rpx;
					}
				}

				.tell {
					color: #333333;
					font-weight: 700;
					font-size: 32rpx;
					margin-top: 20rpx;
				}
			}

			.notice-tips {
				margin-top: 30rpx;
				padding: 30rpx;
				background-color: #fff;
				border-radius: 30rpx;

				.notice {
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.guarantee {
					margin-top: 20rpx;
					color: #999999;
					font-size: 24rpx;
				}
			}

			.order {
				margin-top: 30rpx;
				padding: 30rpx;
				background-color: #fff;
				border-radius: 30rpx;
				color: #333333;

				.order-title {
					font-size: 28rpx;
					font-weight: 700;
				}

				.order-info {
					margin-top: 30rpx;

					.info-item {
						margin-top: 10rpx;
						font-size: 24rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;

						image {
							width: 22rpx;
							height: 22rpx;
						}
					}
				}
			}
		}

		.merchants {
			width: 100%;
			padding: 20rpx 0;
			color: #ffffff;
			font-size: 28rpx;
			font-weight: 700;
			background: linear-gradient(90deg, #C58AF0 0%, #6272ED 100%);
			text-align: center;
			box-shadow: 5rpx 5rpx 5rpx #cacaca;
			margin-top: 40rpx;
			border-radius: 50rpx;
		}

		.btn-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			.btn1 {
				width: 48%;
				padding: 20rpx 0;
				color: #ffffff;
				font-size: 28rpx;
				font-weight: 700;
				background: #bfbfbf;
				text-align: center;
				box-shadow: 5rpx 5rpx 5rpx #cacaca;
				border-radius: 50rpx;
				margin-top: 30rpx;
			}
			.btn2 {
				width: 48%;
				padding: 20rpx 0;
				color: #ffffff;
				font-size: 28rpx;
				font-weight: 700;
				background: linear-gradient(90deg, #C58AF0 0%, #6272ED 100%);
				text-align: center;
				box-shadow: 5rpx 5rpx 5rpx #cacaca;
				border-radius: 50rpx;
				margin-top: 30rpx;
			}
		}
	}
</style>